home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple II Magazines (PO)
/
Nibble Volume 10, No. 05 (1989-05)(MicroSPARC)(Side A)[a].zip
/
Nibble Volume 10, No. 05 (1989-05)(MicroSPARC)(Side A)[a].po
/
RESET.S.txt
< prev
next >
Wrap
Text File
|
1996-12-24
|
15KB
|
330 lines
**************************
* RESET.OBJ SOURCE CODE *
* BY KENN SCRIBNER *
* COPYRIGHT (C) 1989 *
* MICROSPARC, INC. *
* CONCORD, MA 01742 *
**************************
*
*
* ORCA/M 4.1 Assembler
*
ORG $6EC7
KEEP RESET
RESET START
;...............................................................
;
; Program EQUates.
;...............................................................
CSWL EQU $36 ;monitor character output hook
KSWL EQU $38 ;monitor character input hook
VBL1 EQU $3C ;temporary storage location
VBL2 EQU $3D ;temporary storage location
VBL3 EQU $3E ;temporary storage location
VBL4 EQU $3F ;temporary storage location
A1L EQU $3C ;source starting address for MOVE
A2L EQU $3E ;source ending address for MOVE
A4L EQU $42 ;destination address for MOVE
LINNUM EQU $50 ;ASoft line number in progress
CURLIN EQU $75 ;ASoft line number in progress
VARPNT EQU $83 ;pointer to ASoft variable data
TXTPTR EQU $B8 ;current ASoft token's address
ERRPOS EQU $DC ;temporary storage for TXTPTR
INBUFR EQU $200 ;DOS command input buffer
RSTVCTL EQU $3F2 ;reset vector low byte
RSTVCTH EQU $3F3 ;reset vector high byte
RSTVCTV EQU $3F4 ;reset vector power-up validation byte
ERROR EQU $D412 ;ASoft error handler, errnum in xreg
STKINI EQU $D683 ;restore ASoft's stack pointer
STXTPT EQU $D697 ;reset TXTPTR to beginning of program
NEWSTT EQU $D7D2 ;execute ASoft program from TXTPTR
GETLIN EQU $D941 ;find line in LINNUM in memory
PTRGET EQU $DFE3 ;find/create simple variable in memory
GIVAYF EQU $E2F2 ;convert integer in A,Y to floating pt.
GETADR EQU $E752 ;convert floating pt. number to integer
MOVFM EQU $EAF9 ;unpack variable data and move to FAC
MOVMF EQU $EB2B ;pack FAC data and move to variable
SETHMEM1 EQU $F28E ;calculate and set HIMEM from LINNUM
MOVE EQU $FE2C ;monitor memory move routine
;...............................................................
;
; ProDOS and BASIC.SYSTEM EQUates.
;...............................................................
DOSCMD EQU $BE03 ;execute DOS command stored at $200
ERROUT EQU $BE09 ;BASIC.SYSTEM error handler
VECTOUT EQU $BE30 ;BASIC.SYSTEM output link
VECTIN EQU $BE32 ;BASIC.SYSTEM input link
GETBUFR EQU $BEF5 ;reserve x pages above HIMEM, x in areg
KVERSION EQU $BFFF ;ProDOS Kernel Version
;...............................................................
;
; DOS 3.3 EQUates.
;...............................................................
CONNECT EQU $3EA ;DOS 3.3 I/O vector reconnection routine
MAXFILES EQU $A258 ;DOS 3.3 MAXFILES command
CLOSE EQU $A316 ;close all open DOS 3.3 files
;...............................................................
;
; Set up SV variable.
;...............................................................
LDA #>SETUP ;variable data high byte
STA VBL1 ;store it for subroutine
LDA #<SETUP ;variable data low byte
STA VBL2 ;store it
LDA #>SVVBL ;variable name's location high byte
STA VBL3 ;store it
LDA #<SVVBL ;variable name's location low byte
STA VBL4 ;store it
JSR SETVBL ;set up the variable
RTS ;done, let user initialize reset pgm
;...............................................................
;
; Set up RE variable.
;...............................................................
SETUP LDA #$03 ;ASoft equivalent of LET RE = 1000
STA VBL1
LDA #$E8 ; ($03E8 = 1000 decimal)
STA VBL2
LDA #>REVBL ;NOTE: this overwrites any previous
STA VBL3 ; RE values!
LDA #<REVBL
STA VBL4
JSR SETVBL ;create/change variable
LDA CSWL ;save I/O links so DOS may be recon-
STA RST+1 ; nected after a reset.
LDA CSWL+1 ;saving output links
STA RST+5
LDA KSWL ;saving input links
STA RST+9
LDA KSWL+1
STA RST+13
CHKDOS LDA KVERSION ;check which DOS we're running
BMI DOS33 ;running DOS 3.3
PDOS LDA #$01 ;want 1 page (256 bytes) of reserved
JSR GETBUFR ; space (moves HIMEM and protects us)
BCC FIXPGM ;enough memory, okay to relocate pgm
MEMERR LDX #$4D ;?OUT OF MEMORY error
JMP ERROR ;not enough memory, flag user
;...............................................................
;
; This code "fixes" our program, since we don't know beforehand where
; BASIC.SYSTEM will want it moved.
;...............................................................
FIXPGM STA FIX1+1 ;we need to correct any absolute
STA FIX2+1 ; addresses to properly relocate code
STA CLSLOOP+2
STA SETVECT+6 ;new reset vector's value (high byte)
STA A4L+1 ;high byte of memory to relocate to
LDA #$BE
STA KILLVECT+6 ;point KV to $BE00
LDA #$00 ;low byte of memory to relocate to
STA A4L
STA KILLVECT+1
LDA #<RST ;beginning of program to be moved
STA A1L
LDA #>RST
STA A1L+1
LDA #<END ;ending of program to be moved
STA A2L
LDA #>END
STA A2L+1
LDY #$00
JSR MOVE ;move program
;...............................................................
;
; Set up KV and SV, kill vector and set vector for ProDOS version.
;...............................................................
LDA FIX1+1 ;get high byte of set routine
STA VBL1 ; (corrected for BASIC.SYSTEM move)
LDA #<KILLVECT
STA VBL2
LDA #>KVVBL ;find variable's name
STA VBL3
LDA #<KVVBL
STA VBL4
JSR SETVBL ;create/change KV
LDA FIX1+1 ;get high byte of set routine
STA VBL1 ; (corrected for BASIC.SYSTEM move)
LDA #<SETVECT
STA VBL2
LDA #>SVVBL ;find variable's name
STA VBL3
LDA #<SVVBL
STA VBL4
JSR SETVBL ;create/change SV
BCC FIXVECT ;twiddle reset vector
;...............................................................
;
; DOS 3.3 version. We always know the reset program will load at
; $9600, so we won't need to fix it.
;...............................................................
DOS33 LDA #$01 ;MAXFILES = 1 command
JSR MAXFILES
LDA #$00 ;set HIMEM to $9600
STA LINNUM
LDA #$96
STA LINNUM+1
JSR SETHMEM1 ;calculate and set new HIMEM
LDA #$00 ;low byte of memory to relocate to
STA A4L
LDA #$96 ;high byte of memory to relocate to
STA A4L+1
LDA #<RST ;beginning of program to be moved
STA A1L
LDA #>RST
STA A1L+1
LDA #<END ;ending of program to be moved
STA A2L
LDA #>END
STA A2L+1
LDY #$00
JSR MOVE ;move program
LDA #$96 ;get high byte of kill routine
STA VBL1
LDA #<KILLVECT
STA VBL2
LDA #>KVVBL ;find variable's name
STA VBL3
LDA #<KVVBL
STA VBL4
JSR SETVBL ;create/change KV
LDA #$96 ;get high byte of set routine
STA VBL1
LDA #<SETVECT
STA VBL2
LDA #>SVVBL ;find variable's name
STA VBL3
LDA #<SVVBL
STA VBL4
JSR SETVBL ;create/change SV
;...............................................................
;
; Set up reset vector.
;...............................................................
FIXVECT LDA #$00 ;low byte
STA RSTVCTL
FIX1 LDA #$96 ;(corrected) high byte
STA RSTVCTH
EOR #$A5 ;twiddle power-up byte
STA RSTVCTV
RTS ;done, ASoft reset enabled
;...............................................................
;
; Routine to create/find ASoft variables.
;...............................................................
SETVBL LDA TXTPTR ;save present location in ASoft pgm
STA ERRPOS
LDA TXTPTR+1
STA ERRPOS+1
LDA VBL3 ;retrieve high byte of our variable
STA TXTPTR+1
LDA VBL4 ;retrieve low byte of our variable
STA TXTPTR
JSR PTRGET ;find/create variable
LDA VBL1 ;retrieve high byte's value
LDY VBL2 ;retrieve low data byte's value
JSR GIVAYF
LDX VARPNT
LDY VARPNT+1
JSR MOVMF
LDA ERRPOS ;restore actual location of ASoft pgm
STA TXTPTR
LDA ERRPOS+1
STA TXTPTR+1
CLC ;clear carry to force branch on return
RTS ;done!
;...............................................................
;
; Set and Kill variable names.
;...............................................................
SVVBL DC H'53 56 00' ;"SV"
KVVBL DC H'4B 56 00' ;"KV"
;...............................................................
;
; Reset routine.
;...............................................................
RST LDA #$F0 ;reconnect default I/O links
STA CSWL ;character output
LDA #$FD ; (default 40 columns, COUT = $FDF0)
STA CSWL+1
LDA #$1B ;character input
STA KSWL ; (default keyboard)
LDA #$FD
STA KSWL+1
LDA KVERSION ;are we running ProDOS?
BMI RSTDOS33 ;no, reset for DOS 3.3
LDA #$F0 ;set default BASIC.SYSTEM global vectors
STA VECTOUT ; (character output --> $FDF0, or COUT)
LDA #$FD
STA VECTOUT+1
LDA #$1B ; (character input --> $FD1B, or KEYIN)
STA VECTIN
LDA #$FD
STA VECTIN+1
CLSFILE LDX #$00 ;have BASIC.SYSTEM close all open files
CLSLOOP LDA CLSCMD,X ;(we have BASIC.SYSTEM CLOSE files...
BEQ CLSALL ;...rather than the ProDOS MLI 'cause...
STA INBUFR,X ;...BASIC.SYSTEM does some other...
INX ;...housekeeping the MLI doesn't)
BNE CLSLOOP
CLSCMD DC H'C3 CC CF D3 C5 8D 00' ;"CLOSE", with carriage return and $00
CLSALL JSR DOSCMD
BCC READVBL
LDA #$15 ;FILE(S) STILL OPEN error
JMP ERROUT
RSTDOS33 JSR CONNECT ;reconnect DOS 3.3
JSR CLOSE ;close all open files
READVBL LDA #<REVBL ;retrieve line number from RE
STA TXTPTR
FIX2 LDA #$96 ;byte will be corrected for ProDOS call
STA TXTPTR+1
JSR PTRGET ;find variable data
JSR MOVFM ;move it to the FAC
JSR GETADR ;convert it to integer (in LINNUM)
LDA LINNUM+1 ;get high byte of line number
STA CURLIN+1 ;store it for execution
LDA LINNUM ;get low byte of line num
STA CURLIN ;store it for execution
JSR STKINI ;restore stack
JSR STXTPT ;reset TXTPTR to beginning of program
JSR GETLIN ;find our new line in memory
JMP NEWSTT ;start execution at new line number
;...............................................................
;
; Restore variable name.
;...............................................................
REVBL DC H'52 45 00' ;"RE"
;...............................................................
;
; Routine to re-enable the reset program.
;...............................................................
SETVECT LDA #$00 ;point reset vector to $9600
STA RSTVCTL
LDA #$96 ;will be modified for ProDOS version
STA RSTVCTH
EOR #$A5
STA RSTVCTV
RTS
;...............................................................
;
; Routine to disable the reset program.
;...............................................................
KILLVECT LDA #$BF ;restore reset vector to default values
STA RSTVCTL ;($9DBF for DOS 3.3)
LDA #$9D ;($BE00 for BASIC.SYSTEM, which will...
STA RSTVCTH ;...be inserted here before this code...
EOR #$A5 ;...is relocated)
STA RSTVCTV
END RTS
END